package com.ccrfid.rmc6.service.personnel;

import com.ccrfid.rmc6.appconfig.exception.pojo.AppException;
import com.ccrfid.rmc6.entity.personnel.*;
import com.ccrfid.rmc6.entity.poi.PoiLocationEntity;
import com.ccrfid.rmc6.lbservice3.pojo.msg.MsgLocate;
import com.ccrfid.rmc6.pojo.dto.*;
import com.ccrfid.rmc6.pojo.dto.personnel.AreaCategoryDto;
import com.ccrfid.rmc6.pojo.dto.personnel.PersonnelLocatorDto;
import com.ccrfid.rmc6.pojo.dto.personnel.PrisonerStatisticDto;
import com.ccrfid.rmc6.pojo.dto.visitroom.PersonelTypeCountDto;
import com.ccrfid.rmc6.pojo.param.SortParam;
import com.ccrfid.rmc6.repository.search.SearchCriteria;
import com.vividsolutions.jts.geom.Polygon;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.sql.Timestamp;
import java.util.List;
import java.util.Set;

public interface PersonnelService {
    //
    Page<PersonnelView> getPersonnelInfoPage(SearchCriteria criteria, Pageable pageable);
    List<PersonnelView> getPersonnelInfoList(SearchCriteria criteria, Sort sort);

    //
    Page<PersonnelPrisonerView> getPrisonerInfoPage(SearchCriteria criteria, Pageable pageable);

    //
    List<PersonnelPrisonerView> getPrisonerList(SearchCriteria criteria, Sort sort);
    List<PersonnelPrisonerView> getPrisonerList(Long accountOrgId, Integer enabled, Timestamp comeTimeStart,
                                                Timestamp comeTimeStop, Integer prisonerType, Integer onlineStatus,
                                                SortParam sortParam);

    //
    PersonnelView getPersonnelDetailById(Long personnelId);

    PersonnelView getPersonnelDetailByCardNumber(Long cardNumber);

    //
    PersonnelPrisonerView getPrisonerDetailById(Long personnelId);

    //
    List<PersonnelEntity> getPersonnelListByCardNumberNotNull();

    //
    List<PersonnelEntity> getAllPersonnelsEnabled();

    //
    List<PersonnelView> getPersonnelInfoByLocatorAddressNotNull();
    List<PersonnelView> getPersonnelInfoByLocatorAddress(Integer locatorAddress);

    //
    @Cacheable(value = "personnels", key = "#cardNumber")
    PersonnelEntity getPersonnelByCardNumber(Long cardNumber);

    //
    @Cacheable(value = "personnels2", key = "#personnelId")
    PersonnelEntity getPersonnelById(Long personnelId);

    PersonnelEntity getPersonnelBySn(String personnelSn);

    //
    @Caching(
            put = {
                    @CachePut(value = "personnels", key = "#result.cardNumber", condition = "#result.cardNumber != null"),
                    @CachePut(value = "personnels2", key = "#result.id")
            })
    PersonnelEntity createPersonnel(PersonnelEntity entity) throws AppException;

    //
    @CachePut(value = "personnels2", key = "#result.id")
    PersonnelEntity createPrisoner(NewPrisonerDto dto) throws AppException;

    //
    @Caching(
            put = {
                    @CachePut(value = "personnels", key = "#result.cardNumber", condition = "#result.cardNumber != null"),
                    @CachePut(value = "personnels2", key = "#result.id")
            })
    PersonnelEntity updatePersonnel(Long personnelId, PersonnelEntity entity) throws AppException;

    //
    @Caching(
            evict = {
                    @CacheEvict(value = "personnels", allEntries = true),
                    @CacheEvict(value = "personnels2", allEntries = true)
            }
    )
    int deletePersonnels(List<Long> idList);

    byte[] getPersonnelPhoto(Long personnelId);

    Boolean updatePersonnelPhoto(Long personnelId, byte[] image) throws AppException;

    @Caching(
            evict = {
                    @CacheEvict(value = "personnels", key = "#cardNumber"),
                    @CacheEvict(value = "personnels2", key = "#personnelId")
            }
    )
    Boolean bindPersonnelCard(Long personnelId, Long cardNumber) throws AppException;

    @Caching(
            evict = {
                    @CacheEvict(value = "personnels", key = "#cardNumber"),
                    @CacheEvict(value = "personnels2", key = "#personnelId")
            }
    )
    Boolean unBindPersonnelCard(Long personnelId, Long cardNumber) throws AppException;

    Long countByIdListAndPersonnelType(Set<Long> idList, Integer personnelType);

    PersonnelMoveEntity recordPersonnelMove(Long personnelId, MsgLocate msgLocate);

    Boolean existsByPersonnelId(Long personnelId);

    List<LocatorPersonnelCount> getPersonnelMap(Integer personnelType, Integer floorNumber);

    List<LocatorPersonnelCount> getPrisonerMap(Integer prisonerType, Integer floorNumber);

    PositionDto getPersonnelPosition(Long personnelId);

    PoiLocationEntity getPersonnel3LevelLocation(Long personnelId);

    List<MoveLineDto> getPersonnelMoveLine(Long personnelId, Timestamp startTime, Timestamp endTime);

    PersonnelLocationActivityDto getLevel3LocationActivity(Long trackId);

    List<PersonnelStatisticDto> getPersonnelStatisticList();

    PrisonerStatisticDto getPrisonerStatistic(Long accountOrgId);

    List<PersonnelPositionView> getPersonnelsInPolygon(Integer floorNumber, Polygon polygon);

    PersonnelLocatorDto getPersonnelLocatorInfo(String personnelSn) throws AppException;

    List<PersonnelLocatorDto> getAllPersonnelLocatorInfo();

    List<AreaCateGoryLocationDto> getPersonnelArea(String locationSnList);

    CardStatusDto getCardStatus();

    CardStatusDto getCardStatusHuaihua(Long orgId);

    List<PersonelAllTypeCountDto> getPersonnelTypeCount();

    ZcPersonnelDto getZCPeronnelCount();

    List<PersonnelOnlineCountDto> getPersonnelOnlineCount();

    PersonnelCountByLocationTotalDto getPersonnelCountByLocator(Integer personnelType,Integer locationId, Long orgId);
    PersonnelCountByLocationTotalDto getPersonnelCountByLocator2(Integer personnelType,Integer locationId, Long orgId);

    Long getFocusedPrisonerCount(Long orgId);

    List<PersonnelCountByOrgDto> getPersonnelCountByOrg(Long orgId);

    List<PersonnelCountDetailByOrgDto> getPersonnelCountDetailByOrg(Long orgId);

    Page<PersonnelCountByLocationTypeDto> getPersonnelCountByLocationType(int locationType, Long orgId, Pageable pageable);

    PersonnelCountForAppDtp getAppHomePageData(Long orgId,Long notifyPersonnelId);

    Page<LocationPersonnelDetailForAppDto> getActualPersonnelsInfoInLocation(Long locationId, Long orgId, Pageable pageable);

    List<PersonnelDetailByOrgDto> getPersonnelDetailByOrg(Long orgId);

    String getAppVersion();

    Page<LocationPersonnelDetailForAppDto> getPersonnelDetailByLocatorType(int locationType, Long orgId, Pageable pageable);

    List<PersonnelCountByLocationTypeDto> getCountByLocationType(Long orgId);

    Page<LocationPersonnelDetailForAppDto> getPersonnelForApp(String personnelName, Long cardNumber, Long orgId, Pageable pageable);

    List<UntreatedPersonDetailDto> getUntreatedPersonDetail(Long orgId);

    List<LocationPersonnelDetailDto> getPersonDetail(Long orgId,String typeList, Integer flag);
    List<LocationPersonnelDetailDto> getPersonDetail2(Long orgId, String typeList, Integer flag);
}
